<%@ page contentType="text/html; charset=UTF-8"%>
<%
int currentPage = 1;
if(null!=request.getParameter("currentPage")){
	currentPage = Integer.parseInt(request.getParameter("currentPage"));
	if(currentPage<1){
		currentPage = 1;
	}
}

//总记录数
int totalRecord = Integer.parseInt(request.getParameter("totalRecord"));
String formName = request.getParameter("formName");

int pageSize = 10;
String url = request.getParameter("url");
if( null!=request.getParameter("pageSize")){
	pageSize = Integer.parseInt(request.getParameter("pageSize"));
}

int totalPage = 0;
if(totalRecord % pageSize != 0){
	totalPage = totalRecord / pageSize +1;
}else{
	totalPage = totalRecord / pageSize;
}
if(currentPage>totalPage){
	currentPage = totalPage;
}

//计算最小页数
int p = 0 ;
if(currentPage % 5 != 0){
	p = currentPage / 5;
}else{
	p = currentPage / 5-1;
}




out.print("<table width=98% align=center>");
out.print("<tr>");
out.print("<td style='font-size:12px;'>共<strong> "+totalRecord+" </strong>记录,");
out.print("共 <strong>"+totalPage+"</strong>页,");
out.print("当前第<strong> "+currentPage+" </strong>页</td>");
out.print("<td align='right' style='font-size:12px;'><a href='javascript:first()' id='first' name='first' target='_self'>首页</a>&nbsp;");
out.print("<a href='javascript:previous();' id='previous' name='previous' target='_self'>上一页</a>&nbsp;"); 
out.print("<a href='javascript:next()' id='next' name='next' target='_self'>下一页</a> &nbsp;");
out.print("<a href='javascript:last()' id='last' name='last' target='_self'>末页</a>&nbsp;");
out.print("<input type='text' name='currentPage' id='currentPage' value='"+currentPage+"' style='width:18px;'>页&nbsp;");
out.print("<input name='aa' type='button' onClick=\"submitPage2('"+formName+"')\" value='GO'></td>");
out.print("</tr></table>");

%>
<script type="text/javascript">
function first(){
	document.getElementById("currentPage").value=1;
	document.<%=formName%>.submit();
}

function last(){
	document.getElementById("currentPage").value=<%=totalPage%>;
	document.<%=formName%>.submit();
}

function previous(){
	var currentPage = document.getElementById("currentPage").value;
	if(currentPage<=1){
		alert("已经是第一页！");
		return;
	}
	document.getElementById("currentPage").value = <%=currentPage-1%>;
	document.<%=formName%>.submit();
}

function next(){
	var currentPage = document.getElementById("currentPage").value;
	if(currentPage>=<%=totalPage%>){
		alert("已经是最后一页！");
		return;
	}
	document.getElementById("currentPage").value = <%=currentPage+1%>;
	document.<%=formName%>.submit();
}

function submitPage(currPage,formName)
{ 
	document.getElementById("currentPage").value=currPage;
	document.<%=formName%>.submit();
}

function submitPage2(formName){
	var curr = document.getElementById("currentPage").value;
	var numReg = /^[1-9]+([0-9]*)$/;
	if(!numReg.test(curr)){
		alert("请输入大约零的整数！");
		return;
	}
	document.<%=formName%>.submit();
}
</script>